package com.kx.ssm.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.kx.ssm.constants.ResultCode;

/**
 * @ClassName R
 * @Author Sun
 * @Date 2021/5/20 22:36
 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class R {
    private int code;
    private String msg;
    private Object data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static R setOK(){
        R r = new R();
        r.setCode(ResultCode.SUCCESS);
        r.setMsg("成功");
        r.setData(null);
        return r;
    }

    public static R setOK(Object data){
        R r = new R();
        r.setCode(ResultCode.SUCCESS);
        r.setMsg("成功");
        r.setData(data);
        return r;
    }

    public static R setError(int code,String msg,Object data){
        R r = new R();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static R setError(int code,String msg){
        return setError(code, msg, null);
    }
    public static R setError(){
        R r = new R();
        r.setCode(ResultCode.FAIL);
        r.setMsg("失败");
        return r;
    }

}
